# Create your views here.
import json

from .modules.db_async import SyncDatabase, DataBase


def sync_database(requests):
    params = json.loads(requests.body.decode("utf-8"))
    schema = params["schema"]
    src_config = params["src_config"]
    dst_config = params["dst_config"]
    override = params.get("override", True)
    include_tables = params.get("include_tables", [])
    exclude_tables = params.get("exclude_tables", [])

    src_config = {
        'db': "sessionmydata",
        'user': 'root',
        'password': 'mYLu_20x',
        'host': '172.22.69.171',
        'port': 3306,
    }
    dst_config = {
        'db': "lufndssnmydata",
        'user': 'root',
        'password': 'mYLu_20x',
        'host': '172.22.71.163',
        'port': 3306,
    }



    session = SyncDatabase(
        DataBase(src_config),
        DataBase(dst_config),
        coroutine=10,
        override=override,
        include_tables=include_tables,
        exclude_tables=exclude_tables,
    )
    session.run()
